@extends('layouts.default')

@section('title')
	小区管理
@stop

@section('pre')
	<li class="active"><span>@yield('title')</span></li>
@stop

@section('css')
@stop

@section('content')

<div class="row">
	<div class="col-lg-12">
		<div class="main-box">
			<header class="main-box-header clearfix">
			@if ( isset($groupData) && !empty($groupData) )
			<h2>请选择一个小区</h2>
			</header>
			<div class="main-box-body clearfix">
				<form role="form">
					<div class="col-lg-12">
						<div class="btn-group" data-toggle="buttons" id="group-ids">
                        @foreach ($groupData as $key => $name)
                        	@if( isset($active) && $key == $active )
                            <label class="btn btn-primary active">
                            @else
							<label class="btn btn-primary">
                            @endif
                                <input type="radio" name="options" id="{{ $key }}"> {{ $name }}
                            </label>
                        @endforeach
						</div>
					</div>
				</form>
			</div>
			@else
			<h2>您当前还没有小区,<a href="{{ url('groupCreate') }}">点此</a>创建一个</h2>
			</header>
			@endif
		</div>
	</div>
</div>

@if ( isset( $active ) )
<div class="row">
	<div class="col-lg-12">
		<div class="main-box">
			<header class="main-box-header clearfix">
			<h2 id="group-name-title"></h2>
			</header>
			<div class="main-box-body clearfix">
				<form role="form" method="post" action="{{ url('groupArrange') . '/' . $active }}">
					<div class="form-group form-group-select2">
						<label>小区设备集合</label>
						<select style="width:300px" id="sel2Multi" name="devices[]" multiple>
						@if ( isset( $unGroupDevs ) && !empty( $unGroupDevs ) )
							@foreach ($unGroupDevs as $id => $val)
								<option value="{{ $id }}">{{ $val }}</option>
							@endforeach
						@endif
						</select>
					</div>
					<div class="col-lg-12" style="text-align: center;">
						<br/>
						<input type="submit" class="btn btn-primary" name="edit" value="修改">
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
@endif

@stop

@section('js')

	<script type="text/javascript">
		
		jQuery(document).ready(function() {

			$('#sel2Multi').select2({
				placeholder: '暂无设备',
				allowClear: true
			});

			//写入当前select
			@if( isset($groupDevs) && !empty($groupDevs) )
				$('#sel2Multi').val({{ $groupDevs }}).trigger("change");
			@endif

			//详情
	        $("#group-ids > label").on('click', function(){

	        	var id = $(this).find('input:radio').attr('id');

	            //跳转
	            var uri = "{{ url('groupArrange') }}";

	            window.location.href = uri + '/' + id;

	        });
	    });

	</script>

@stop